Rappahannock Community College STEM Camp
  • Home
  • 2021 STEM Camp
    • PreAcademy prep
    • Day 1: Measuring Your Pulse >
      • Day 1 Supplemental Activity:
    • Day 2: Ultrasound >
      • Day 2: Supplement: Touchless Soap Dispenser
    • Day 3: Galvanic Skin Response >
      • Day 3 Supplement: IR Temp Sensor
    • Day 4: Pulse Oximeter >
      • Day 4 Supplemental Activity:
    • Day 5 Friday: Finishing up/Show
    • Future lesson to move
  • Shared Google Folder
  • The Teachers
  • Archive
    • Pictures from prior years
    • 2020 STEM Camp >
      • Home (2020)
      • The 2020 Teachers
      • PreAcademy prep
      • Day 1 Monday: Basics and Lights >
        • Day 1 Supplement Activity
      • Day 2 Tuesday: Servos >
        • Day 2 (Suppliment Activities)
      • Day 3 Wednesday: Making an ECG/EKG! >
        • Day 3 (Supplement Page)
      • Day 4 Thursday: Controlling Servos with EMG >
        • Day 4 Supplemental Activity
      • Day 5 Friday: Finishing up/Show >
        • Unused lessons/content
    • 2018 Lessons >
      • Day 1 (Monday)
      • Day 2 (Tuesday)
      • Day 3 (Wednesday)
      • Day 4 (Thursday)
      • Day 5 (Friday)
    • 2017 Camp >
      • Day 1 (Monday)
      • Day 2 (Tuesday)
      • Day 3 (Wednesday)
      • Day 4 (Thursday)
      • Day 5 (Friday)
    • Pictures archive for lessons (some graphic images)
  • Contact Us!

IR Servo Touchless Soap Dispenser

1 Motor Version 

_______________________________________________________________________________________
#include "Servo.h" //Include Servo Motor library for using Servo
Servo myServo1;
#define in A0
int servo1 = A1; //Digital PWM pin used by the servo 1

void setup() {
Serial.begin(9600);
Serial.println("Hello");
myServo1.attach(servo1);
pinMode(in, INPUT);
}

void loop() {
 if(digitalRead(in)){
 Serial.println("Active");
 myServo1.write(110);
 delay(300);
  }

​ else{
 Serial.println("Inactive");
 myServo1.write(0);
  }

delay(5);
}

2 Motor version

Code: 

#include "Servo.h" //Include Servo Motor library for using Servo
Servo myServo1;
Servo myServo2;
#define in A0
int servo1 = A1; //Digital PWM pin used by the servo 1
int servo2 = A2; //Digital PWM pin used by the servo 2

void setup()
{
Serial.begin(9600);
Serial.println("Hello");
myServo1.attach(servo1);
myServo2.attach(servo2);
pinMode(in, INPUT);
}

void loop()
{
if(digitalRead(in)){
Serial.println("Active");
myServo1.write(110);
myServo2.write(0);
delay(300);
}

​else{
Serial.println("Inactive");
myServo1.write(0);
myServo2.write(110);
}
delay(5);
}
Powered by Create your own unique website with customizable templates.
  • Home
  • 2021 STEM Camp
    • PreAcademy prep
    • Day 1: Measuring Your Pulse >
      • Day 1 Supplemental Activity:
    • Day 2: Ultrasound >
      • Day 2: Supplement: Touchless Soap Dispenser
    • Day 3: Galvanic Skin Response >
      • Day 3 Supplement: IR Temp Sensor
    • Day 4: Pulse Oximeter >
      • Day 4 Supplemental Activity:
    • Day 5 Friday: Finishing up/Show
    • Future lesson to move
  • Shared Google Folder
  • The Teachers
  • Archive
    • Pictures from prior years
    • 2020 STEM Camp >
      • Home (2020)
      • The 2020 Teachers
      • PreAcademy prep
      • Day 1 Monday: Basics and Lights >
        • Day 1 Supplement Activity
      • Day 2 Tuesday: Servos >
        • Day 2 (Suppliment Activities)
      • Day 3 Wednesday: Making an ECG/EKG! >
        • Day 3 (Supplement Page)
      • Day 4 Thursday: Controlling Servos with EMG >
        • Day 4 Supplemental Activity
      • Day 5 Friday: Finishing up/Show >
        • Unused lessons/content
    • 2018 Lessons >
      • Day 1 (Monday)
      • Day 2 (Tuesday)
      • Day 3 (Wednesday)
      • Day 4 (Thursday)
      • Day 5 (Friday)
    • 2017 Camp >
      • Day 1 (Monday)
      • Day 2 (Tuesday)
      • Day 3 (Wednesday)
      • Day 4 (Thursday)
      • Day 5 (Friday)
    • Pictures archive for lessons (some graphic images)
  • Contact Us!