Advanced Search
Search Results
139 total results found
How to use a PIR sensor
... // PIR status void setup() { pinMode(ledPin, OUT ... Serial.begin(9600); } void loop(){ pirStat = digitalRead(pirPin); if (pirStat == HIGH) { // if motion detected digitalWrite(ledPin, HIGH); // turn...
How to use a Hall Effect Sensor
... store the state of the sensor void setup() { Serial.begin(9600); ...ffect sensor pin as an INPUT } void loop() { hallSensorState = digitalRead(hallSensorPin); // Read the state of the sensor Serial.println(hallSensorState); delay(100); }
How to build a Simple Robot Arm with Servo Motor and Joystick
...D Workshop to laser cut the hardware. In this tutorial, we will fo ...ateServo; Servo angleServo; void setup() { Serial.begin(9600) ...gleServo.attach(servoAngle); } void loop() { // read analog potentiometer values int rotation = analogRead(po...
Controlling an actuator with a N-channel Mosfet
...ce. #define actuatorPin 13 void setup() { pinMode( actuat ...orPin, OUTPUT ); } void loop() { digitalWrite( actuatorPin, HIGH ); delay( 1000 ); digitalWrite( actuatorPin, LOW ); delay( 1000 ); }
Using a Force Sensor
... hard touch int limit = 200; void setup() { Serial.begin(9600); ... pinMode(13, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); Serial.print("Force Level: "); Serial.println(sensorValue); if (sensorValue > limit) { digitalWrite...
Using a Soil Moisture Sensor
...od range of moisture generally void setup() { Serial.begin(9600); ... pinMode(13, OUTPUT); } void loop() { sensorValue = analogRead(sensorPin); Serial.print("Moisture Level: "); Serial.println(sensorValue); if (sensorValue < limit) { digitalWr...
Using an MFRC522 RFID reader
...h each identification and a two-way radio transmitter-receiver as ...); // Create MFRC522 instance void setup() { Serial.begin(9600); ...type, and data blocks...")); } void loop() { // Reset the loop if no new card is present on the sensor/reader. T...
How to fix "Internal data stream error" in Processing 4
...cessing.video.*; Capture cam; void setup() { size(640, 480); ... cam.start(); } } void draw() { if (cam.available() == true) { cam.read(); } image(cam, 0, 0); // The following does the same, and is faster when just drawing...
How to connect a Light Dependent Resistor (LDR)
...drPin A0 int value; int limit; void setup() { Serial.begin( 9600 ...Mode(LED_BUILTIN, OUTPUT); } void loop() { value = analogRead( ldrPin ); Serial.println( value ); if(value < limit){ digitalWrite(LED_BUILTIN, HIGH); }else{ dig...
Using a Membrane Potentiometer (SoftPot)
...the built-in LED when touched lightly. int SOFT_POT_PIN = A0; void setup() { Serial.begin(9600) ...inMode(SOFT_POT_PIN, INPUT); } void loop() { int softPotPosition = analogRead(SOFT_POT_PIN); Serial.println(softPotPosition); delay(100); }
Using a HC-SR04 distance sensor
...if the ping sound is reflected away from the sensor by an a diverg ...nsor distanceSensor(13, 12); void setup () { Serial.begin(960 ...or. pinMode(13, OUTPUT); } void loop () { float distance = distanceSensor.measureDistanceCm(); Seria...
Using built-in example code and Reading the hookup diagram
...t, you will see two main parts, void setup() {} and void loop() {}, this is the main structure of Arduino code. In the setup(), usually we establish what component we are going to control and what are they. pinMode(LED_BUILTIN, OUTPUT); we are using the b...
How to use a Flat Vibration Switch
...-in LED on most Arduino boards void setup() { Serial.begin(9600 ...); } void loop() { int state = digitalRead(vibrationPin); if (state == HIGH) { digitalWrite(ledPin, HIGH); Serial.println("Vibration detected!"); } else { digitalWri...
Using a Whadda Vibration Motor Module
...otor to vibrate for 1 second and stop for 1 second. int motorPin = 13; //motor transistor is connected to pin 3 void setup() { pinMode(motorPin, O ...UTPUT); } void loop() { digitalWrite(motorPi ...stop vibrating delay(1000); //wait 50 seconds. }
How to use a Reed Switch
...= 13; // LED pin - active-high void setup() { Serial.begin(9600) ... pinMode(LED_PIN, OUTPUT); } void loop() { int proximity = digitalRead(REED_PIN); // Read the state of the switch if (proximity == LOW) // If the pin reads low, the switch is c...
How to use an Electromagnet
...net connected to digital pin 2 void setup() { pinMode(electromagn ...OUTPUT Serial.begin(9600); } void loop() { // Turn the electromagnet ON digitalWrite(electromagnetPin, HIGH); Serial.println("Electromagnet ON"); delay(2000); // Turn the...
How to use a EMG Muscle Sensor
...ER_SIZE]; int data_index, sum; void setup() { // Serial connectio ...00); pinMode(13, OUTPUT); } void loop() { static unsigned long past = 0; unsigned long present = micros(); unsigned long interval = present - past; past = present; stati...
Week 2 - Animation, conditionals & random numbers
... detail. A variable is simply a way of storing information in the ...tions. 5 - The value which we want to store in the computer's me ... and single (=) equals signs Always be sure to use the double equ ...he ball when it bounces off the wall Move up and down instead of ...