Hi. today i`m going to show you how to use the GPIO or pins on Arduino it doesn't matter witch one as long as it has GPIO.
First jumper weirs:
Next you need a device to code with:
And you need a Arduino:
Now you need a sensor any: motion, light and distance. Also a led(NOT high powered, ! warning if you put the led in the wrong direction it may break the led or your board ) Put led in with the long side in positive and the short in negative:
Setup:
So now when you have all of the required materials set them down on your table and make sure to know which sensor you chose. Next switch to your Arduino and find the GND pin and 5v or 3v pin. If you have a motion sensor plug the vcc into five volts pin: note, that is a GPIO. while plunging these in you will be using the jumper wires. Now apply the GND pin to the GND pin on the board. Great now you have given power to your sensor. now the only pin open should be the signal pin. They say different things depending on the brand so i cant really say the name. So connect that pin on the sensor to pin 2 on the board: note that is a GPIO. Now I'll explain the light sensor. The average light sensor has two pins. I won`t go into detail of what the sensor does, but i might do it in the future, So connect the power pin of the sensor two 5v or 3v, 5v recommended. now connect the other end into pin 2: note this is a GPIO. now you have finished setting the sensor.
LED setup:
now grab your led and connect the long end into pin 4: note another GPIO. Now finally connect the short end into GND on your board.
Hooray you made it to the last step... The code.
I`m using c++ if you don`t have a c++ editor here is a link to a code converter https://www.codeconvert.ai/c++-to-python-converter
/*
Arduino with PIR motion sensor or light sensor
for viewers
Modified by @delucas based on PIR sensor or light sensor
simplified with no reading values
*/
int led = 4; // led variable
int sensor = 2; // sensor variable - middle out pin in sensor
void setup() {
pinMode(led, OUTPUT); // LED as is an output
pinMode(sensor, INPUT); // sensor is as an input
Serial.begin(9600); // initialize serial
}
void loop(){
if (sensor == HIGH) { // check if the sensor is HIGH
digitalWrite(led, HIGH); // turn LED ON
Serial.println("Motion sensed!");
delay(100); // delay 100 milliseconds
digitalWrite(led, LOW); // turn LED OFF
delay(200); // delay 200 milliseconds
}
}
Any problems with the code please tell me.
Thank you for participating in this!
here is the wire setup:
This page (Using GPIO on Arduino.) was last updated on May 01, 2024.