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:
![Angled shot of Premium Female/Male 'Extension' Jumper Wires - 40 x 3 (75mm)](https://cdn-shop.adafruit.com/640x480/825-04.jpg)
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:
![Single LED lit up red - 5mm.](https://cdn-shop.adafruit.com/640x480/297-00.jpg)
![PIR (motion) sensor with a cable around it.](https://cdn-shop.adafruit.com/640x480/189-00.jpg)
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:
![Screenshot_2024-05-01_15.53.17.png](https://cdn-learn.adafruit.com/user_assets/assets/000/000/871/large1024/Screenshot_2024-05-01_15.53.17.png?1714595980)