Arque Technologies STEM Robotics Series

Four ArduinoSensor Projects

Build a parking sensor, a joystick-controlled servo arm, a comfort monitor with a relay fan switch and a hands-free dustbin, all from one starter kit.

You’ll use
  • Arduino UNO
  • HC-SR04
  • Joystick
  • SG-90 servo
  • DHT-11
  • Relay
  • IR sensor
Try all four
wall + HC-SR04 80 cm RGB LED Joystick: drag the knob 180°0°90° SG-90 servo LED 25.0°C 55% DHT-11 RGB LED Relayclick! “fan” LED servo IR sensor LED Buzzer
touchingfar away
Play the buzzer sound
Distance –
Status –

Meet the parts

PartJobProjects
Arduino UNO (SMD, FT232 USB) + USB A-to-B cableRuns the code; USB also powers everythingAll
400-point breadboardShares 5V and GND between the modulesAll
Resistor pack220 Ω for each LED and RGB colour1, 2, 3, 4
Capacitor packA 100–470 µF capacitor steadies the 5V supply when the servo moves2, 4
Ultrasonic sensor moduleMeasures distance (the HC-SR04)1
RGB LED, 5 mm, 4 legsGreen / yellow / red, or blue / green / red1, 3
Buzzer B-10Beeps1, 2, 4
PS2 joystick moduleTwo analog axes and a push button2
SG-90 servo motorTurns to an exact angle2, 4
LED, 5 mmBrightness control, “fan” light or “lid open” light2, 3, 4
DHT-11 sensorTemperature and humidity3
5V relay moduleA switch the Arduino can click on and off3
IR sensor module (LM358)Notices a hand in front of it4
7805 voltage regulatorNot used here: it turns 7–12 V into 5 V, and this kit has no 7–12 V supply–
VCCTRIGECHOGNDHC-SR04ultrasonic distanceVCCGNDOUTIR sensorscrew sets rangeVCCDATAGNDDHT-11pin order variesGND+5VVRxVRySWJoystickpress = SW buttonGND5VSIGSG-90 servobrown · red · orangeNOCOMNCVCCGNDINRelay moduleneeds the small boardR−GBRGB LEDlongest leg = common+ long−LEDalways add a resistor+ long− stripeCapacitor100–470 µF7805INGNDOUT7805 regulatornot used here
Pin orders vary between makers. Always follow the labels printed on your own modules.

Check your relayProject 3 needs a relay module: a relay on a small board with VCC, GND and IN pins. A bare relay on its own can’t be driven from an Arduino pin without a transistor and a diode, which this kit doesn’t include.

About the ultrasonic sensorThe kit list calls it “HC-SR504”. It’s the common HC-SR04 ultrasonic module: four pins marked VCC, TRIG, ECHO and GND.

Setup and power

  1. Install the Arduino IDEThe Servo library is built in. Project 3 also needs the DHT sensor library by Adafruit: install it from the Library Manager and accept Adafruit Unified Sensor when asked.
  2. Connect the UNOThis board uses an FT232 USB chip. If no port appears, install the FTDI driver.
  3. Pick the board and portChoose Tools → Board → Arduino Uno, then the Port that appears when you plug it in.

One pin plan for all four projects

Every part has its own pin, so you can leave modules plugged in when you move to the next project.

PinPartProjects
D2IR sensor OUT4
D3Servo signal (orange)2, 4
D4DHT-11 DATA3
D5LED, through 220 Ω2, 4
D6 / D9 / D10RGB blue / red / green, each through 220 Ω1, 3
D7Relay module IN3
D8Buzzer +1, 2, 4
D11 / D12HC-SR04 ECHO / TRIG1
A0 / A1 / A2Joystick VRx / VRy / SW2
5V, GNDBreadboard + and − rails, shared by every moduleAll

Steady power for the servoA moving servo draws bursts of current that can make the Arduino reset over USB. Put a 100–470 µF capacitor across the 5V and GND rails, long leg to +, as the Project 2 and 4 diagrams show. Never connect the 5V rail straight to GND.

Why the RGB LED is just on or offThe Servo library takes over PWM on pins 9 and 10, and the buzzer’s tone() takes pins 3 and 11. Simple on/off colours (red, green, blue, yellow, purple) avoid both conflicts.

1

Parking sensor

  • HC-SR04
  • RGB LED
  • Buzzer
  • 3 × 220 Ω

Like the sensor in a car bumper: green when the way is clear, yellow with slow beeps as you get closer, red with fast beeps when close, and a non-stop tone at 8 cm.

5V railGND railHC-SR04TRIGECHOVCCGNDRGB LEDR220ΩG220ΩB220ΩGNDBuzzer+GNDArduinoUNOD12D11D9D10D6D85VGNDModules tap the 5V and GND rails on the breadboard. Read the pin labels printed on your modules.
  1. Wire itHC-SR04 TRIG to D12 and ECHO to D11. The RGB LED’s long leg goes to GND; each colour leg gets a 220 Ω resistor to its pin. Buzzer + to D8.
  2. Upload and testOpen the Serial Monitor at 9600 baud and move your hand towards the sensor.
  3. Make it a garageTape the sensor to a box or wall, facing a toy car’s path.
parking_sensor.ino
// PARKING SENSOR: HC-SR04 + RGB LED + buzzer
const int TRIG = 12, ECHO = 11;
const int RED = 9, GREEN = 10, BLUE = 6;
const int BUZZER = 8;
const bool COMMON_ANODE = false;  // true if the RGB long leg goes to 5V

const int SAFE = 50;   // cm: further than this is green and silent
const int NEAR = 20;   // cm: closer than this is red
const int STOP = 8;    // cm: closer than this beeps non-stop

unsigned long lastBeep = 0;

void setColor(bool r, bool g, bool b) {
  if (COMMON_ANODE) { r = !r; g = !g; b = !b; }
  digitalWrite(RED, r); digitalWrite(GREEN, g); digitalWrite(BLUE, b);
}

long readCM() {
  digitalWrite(TRIG, LOW);  delayMicroseconds(2);
  digitalWrite(TRIG, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG, LOW);
  long us = pulseIn(ECHO, HIGH, 30000);  // give up after 30 ms
  if (us == 0) return -1;                // no echo
  return us * 0.0343 / 2;
}

void beepEvery(int gap) {                // short beep every "gap" ms
  if (millis() - lastBeep >= (unsigned long)gap) {
    tone(BUZZER, 1500, 50);
    lastBeep = millis();
  }
}

void setup() {
  pinMode(TRIG, OUTPUT); pinMode(ECHO, INPUT);
  pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  long cm = readCM();
  Serial.print("Distance: ");
  if (cm < 0) Serial.println("no echo");
  else { Serial.print(cm); Serial.println(" cm"); }

  if (cm < 0 || cm > SAFE) {        // clear
    setColor(0, 1, 0);
    noTone(BUZZER);
  } else if (cm > NEAR) {           // getting close: yellow, slow beeps
    setColor(1, 1, 0);
    beepEvery(map(cm, NEAR, SAFE, 150, 600));
  } else if (cm > STOP) {           // close: red, fast beeps
    setColor(1, 0, 0);
    beepEvery(map(cm, STOP, NEAR, 80, 150));
  } else {                          // too close: red, non-stop tone
    setColor(1, 0, 0);
    tone(BUZZER, 1500);
  }
  delay(60);
}
SettingDefaultMeaning
SAFE50 cmFurther away is green and silent
NEAR20 cmCloser turns red with fast beeps
STOP8 cmCloser beeps non-stop
COMMON_ANODEfalseSet true if no colour lights with the long leg on GND (then move it to 5V)
2

Joystick servo arm

  • Joystick
  • SG-90 servo
  • LED
  • Buzzer
  • 220 Ω
  • 470 µF capacitor

Push the stick left and right to swing the servo arm from 0° to 180°. Push up and down to brighten or dim the LED. Hold the stick pressed to send the arm to the centre with a beep. Like a real joystick, it springs back to the middle when you let go, and the arm follows.

5V railGND railJoystickVRxVRySW+5VGNDSG-90 servoorangeredGNDLED+ long220ΩGNDBuzzer+GNDArduinoUNOA0A1A2D3D5D85VGND+ 470 µFModules tap the 5V and GND rails on the breadboard. Read the pin labels printed on your modules.
  1. Wire itJoystick VRx to A0, VRy to A1, SW to A2. Servo orange to D3, red to the 5V rail, brown to GND. LED long leg through 220 Ω to D5. Buzzer + to D8.
  2. Add the capacitorPlace the 470 µF (or the largest 100 µF+ in the pack) across the rails: the long leg in +, the striped side in −.
  3. Upload and playWatch the X and Y numbers in the Serial Monitor: about 512 in the middle, 0 and 1023 at the ends.
joystick_servo.ino
// JOYSTICK SERVO ARM: PS2 joystick + SG90 servo + LED + buzzer
#include <Servo.h>
const int JOY_X = A0, JOY_Y = A1, JOY_SW = A2;
const int SERVO_PIN = 3, LED = 5, BUZZER = 8;

Servo arm;
int lastAngle = -1;

void setup() {
  pinMode(JOY_SW, INPUT_PULLUP);   // pressed = LOW
  pinMode(LED, OUTPUT);
  arm.attach(SERVO_PIN);
  arm.write(90);
  Serial.begin(9600);
}

void loop() {
  int x = analogRead(JOY_X);       // 0-1023, about 512 in the middle
  int y = analogRead(JOY_Y);
  int angle = map(x, 0, 1023, 0, 180);

  if (digitalRead(JOY_SW) == LOW) {  // hold the button: centre the arm
    angle = 90;
    tone(BUZZER, 1200, 60);
  }
  if (abs(angle - lastAngle) > 2) {  // ignore tiny wobbles
    arm.write(angle);
    lastAngle = angle;
  }
  analogWrite(LED, map(y, 0, 1023, 0, 255));  // up/down = brightness

  Serial.print("X: "); Serial.print(x);
  Serial.print("  Y: "); Serial.print(y);
  Serial.print("  angle: "); Serial.println(angle);
  delay(50);
}

Make it your ownTape a paper pointer to the servo horn to build a dial, or a flag that waves. To keep the arm where you leave it, change the code to add a little to the angle while the stick is pushed, instead of mapping the stick directly.

3

Comfort monitor with fan switch

  • DHT-11
  • RGB LED
  • Relay module
  • LED
  • 4 × 220 Ω

The RGB LED shows the room’s feel: blue when cool, green when comfortable, red when hot. When it reaches 30 °C the relay clicks on a “fan”. Here it’s an LED wired through the relay contacts, standing in for a real low-voltage fan.

5V railGND railDHT-11DATAVCCGNDRelay moduleINVCCGNDCOMNO220Ω“fan” LEDRGB LEDR220ΩG220ΩB220ΩGNDArduinoUNOD4D7D9D10D65VGNDModules tap the 5V and GND rails on the breadboard. Read the pin labels printed on your modules.
  1. Install the DHT librarySee Setup above.
  2. Wire itDHT-11 DATA to D4. Relay IN to D7, VCC and GND to the rails. Relay COM to the 5V rail, and NO through 220 Ω to the “fan” LED, then to GND. RGB LED as in Project 1.
  3. Upload and listenThe relay clicks once at start-up as a test. If its LED stays on when it should be off, your module is “low level trigger”: set RELAY_ON = LOW.
  4. Test the fanSet FAN_ON one or two degrees above the room temperature, then warm the DHT-11 gently with your fingers.
  5. Plot itOpen Tools → Serial Plotter to see temperature and humidity as live graphs.
comfort_monitor.ino
// COMFORT MONITOR: DHT11 + RGB LED + relay "fan" switch
#include <DHT.h>
const int DHT_PIN = 4, RELAY = 7;
const int RED = 9, GREEN = 10, BLUE = 6;
const bool COMMON_ANODE = false;  // true if the RGB long leg goes to 5V
const int RELAY_ON = HIGH;        // LOW for "low level trigger" modules
const int RELAY_OFF = (RELAY_ON == HIGH) ? LOW : HIGH;

const float COOL = 20.0;      // °C: below this is blue
const float FAN_ON = 30.0;    // °C: relay switches on at this or above
const float FAN_OFF = 28.0;   // °C: relay switches off below this

DHT dht(DHT_PIN, DHT11);
bool fan = false;

void setColor(bool r, bool g, bool b) {
  if (COMMON_ANODE) { r = !r; g = !g; b = !b; }
  digitalWrite(RED, r); digitalWrite(GREEN, g); digitalWrite(BLUE, b);
}

void setup() {
  pinMode(RED, OUTPUT); pinMode(GREEN, OUTPUT); pinMode(BLUE, OUTPUT);
  pinMode(RELAY, OUTPUT);
  digitalWrite(RELAY, RELAY_ON);  delay(300);  // click test
  digitalWrite(RELAY, RELAY_OFF);
  Serial.begin(9600);
  dht.begin();
}

void loop() {
  delay(2000);                   // the DHT11 needs time between readings
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  if (isnan(t) || isnan(h)) {
    Serial.println("DHT11 read failed");
    setColor(1, 0, 1);           // purple = check the sensor
    return;
  }

  if (t >= FAN_ON) fan = true;   // two limits stop the relay
  if (t < FAN_OFF) fan = false;  // clicking on and off
  digitalWrite(RELAY, fan ? RELAY_ON : RELAY_OFF);

  if (t < COOL)        setColor(0, 0, 1);  // blue: cool
  else if (t < FAN_ON) setColor(0, 1, 0);  // green: comfortable
  else                 setColor(1, 0, 0);  // red: hot

  // "Name:value" pairs also draw lines in the Serial Plotter
  Serial.print("Temp:");     Serial.print(t, 1);
  Serial.print(" Humidity:"); Serial.print(h, 0);
  Serial.print(" Fan:");      Serial.println(fan ? 1 : 0);
}

Low voltage onlyUse the relay only to switch the 5V LED or another small low-voltage device. Never connect mains (wall socket) power to it in a classroom project.

4

Smart dustbin

  • IR sensor
  • SG-90 servo
  • Buzzer
  • LED
  • 220 Ω
  • 470 µF capacitor

Wave a hand in front of the bin and the lid swings open with a beep. It stays open while the hand is there and closes slowly 3 seconds after it leaves.

5V railGND railIR sensorOUTVCCGNDSG-90 servoorangeredGNDBuzzer+GNDLED+ long220ΩGNDArduinoUNOD2D3D8D55VGND+ 470 µFModules tap the 5V and GND rails on the breadboard. Read the pin labels printed on your modules.
  1. Wire itIR sensor OUT to D2. Servo orange to D3, red to 5V, brown to GND. Buzzer + to D8, LED through 220 Ω to D5, and the capacitor across the rails.
  2. Adjust the IR sensorTurn its small screw until its LED lights when your hand is about 10 cm away.
  3. Build the binUse a small box or cup. Tape the servo at the back so its horn lifts a card lid, and mount the IR sensor at the front, facing out.
  4. Tune the anglesChange OPEN and CLOSED so the lid sits flat when closed and clears the hand when open.
smart_dustbin.ino
// SMART DUSTBIN: IR sensor + SG90 servo lid + LED + buzzer
#include <Servo.h>
const int IR_PIN = 2, SERVO_PIN = 3, LED = 5, BUZZER = 8;
const int DETECTED = LOW;        // most IR modules pull OUT low on detection
const int CLOSED = 0, OPEN = 100;  // servo angles for the lid
const unsigned long HOLD = 3000;   // ms to stay open after the hand leaves

Servo lid;
bool isOpen = false;
unsigned long lastSeen = 0;

void moveLid(int from, int to) {   // move slowly so the lid doesn't slam
  if (to > from) { for (int a = from; a <= to; a++) { lid.write(a); delay(8); } }
  else           { for (int a = from; a >= to; a--) { lid.write(a); delay(8); } }
}

void setup() {
  pinMode(IR_PIN, INPUT);
  pinMode(LED, OUTPUT);
  lid.attach(SERVO_PIN);
  lid.write(CLOSED);
  Serial.begin(9600);
  Serial.println("Smart dustbin ready");
}

void loop() {
  bool hand = (digitalRead(IR_PIN) == DETECTED);
  if (hand) lastSeen = millis();

  if (hand && !isOpen) {
    Serial.println("Hand detected: opening");
    tone(BUZZER, 1000, 100);
    digitalWrite(LED, HIGH);
    moveLid(CLOSED, OPEN);
    isOpen = true;
  }
  if (isOpen && !hand && millis() - lastSeen > HOLD) {
    Serial.println("Closing");
    moveLid(OPEN, CLOSED);
    digitalWrite(LED, LOW);
    isOpen = false;
  }
  delay(20);
}

Troubleshooting

No port appears in the Arduino IDE
  • Try another USB cable or port. Some cables only charge.
  • Install the FTDI driver (link in Setup).
The Arduino resets when the servo moves
  • Fit the 100–470 µF capacitor across the 5V and GND rails, long leg to +.
  • Plug into a computer’s USB port directly, not through a hub.
The servo jitters or buzzes at the ends

Some SG-90s can’t reach exactly 0° or 180°. Keep the angles between about 5° and 175°.

The parking sensor always reads “no echo”
  • Check TRIG is on D12 and ECHO on D11 (not swapped).
  • Soft or angled surfaces scatter the sound. Test with a flat book.
The RGB LED shows no colour or the wrong colour
  • No colour: set COMMON_ANODE = true and move the long leg to 5V.
  • Wrong colour: swap the wires on D9, D10 and D6.
“DHT11 read failed” and a purple light
  • Check DATA is on D4 and the module’s VCC and GND.
  • A white sensor is a DHT22: change DHT11 to DHT22 in the code.
The relay never clicks
  • Check its VCC and GND on the rails and IN on D7.
  • Try RELAY_ON = LOW.
The dustbin opens by itself, or never opens
  • Turn the IR sensor’s screw and watch its LED.
  • If it opens when nothing is there, change DETECTED to HIGH.
  • Keep it out of strong sunlight, which contains infrared.
Joystick numbers jump or the arm drifts

Check the joystick’s +5V and GND. Readings around 500–520 at rest are normal; the code ignores changes under 3°.