SUMMER STEM-HEALTH CAMP
  • Home
  • 2025 RCC Camp
    • Day 1: Basic Coding >
      • Button Control
      • Multicolor LED
      • Fading multicolor led
      • Melody (sound)
    • Day 2: Servos and Potentiometers >
      • DC Motor
      • Ultrasound
      • Potentiometer and Motors
      • 2 servo control >
        • Analog Stick Control
      • PIR Motion Sensor
      • IR Light Proximity Sensor
    • Day 3 Making an ECG/EKG! >
      • ECG/EKG health lesson
      • OLED Screen Basics
      • Pictures to OLED
      • BPM on OLED
    • Day 4: Measuring Pulse >
      • Scrolling Screen Graph
      • How the body absorbs light
      • Screen Pictures
      • IR Temp Sensor And Screen
    • Day 5: Finishing up/Show >
      • IR Light Proximity Sensor
      • PIR Motion Sensor
      • CO2 Sensor
      • Ultrasound distance sensor
  • The Teachers
  • Our Partners
  • Archive
    • 2024 Health-STEM Coding Camp >
      • Home (2024)
      • The Teachers
      • Day 1: Basics and Lights
    • 2024 Coding/Robotics Camp >
      • Day 1: Basic Coding >
        • Saving your codes
        • Engineering design
      • Day 2 Servos >
        • 2 Servos, one potentiometer
        • Multicolor LED >
          • Fading multicolor led
    • Pictures from prior years
    • 2023 3D Design Camp >
      • Day 1: 2D design
      • Day 2: 3D design basics
      • Day 3: Constraints
    • 2023 Health-STEM Coding Camp >
      • PreAcademy prep
      • Day 1: Basics and Lights >
        • Multicolor LED
        • Button Control
      • Day 2: Ultrasound >
        • Ultrasound Health Lesson
        • Supplement Melody
        • Supplement: Servo >
          • Potentiometer and Motors
          • 2 servo control
      • Day 3: Measuring Pulse >
        • How the body absorbs light
        • OLED Screen Basics >
          • Scrolling Screen Graph
      • Day 4 Making an ECG/EKG! >
        • ECG Health Lesson
        • Pictures to OLED
        • BPM on OLED
      • Day 5: Finishing up/Show
    • 2021 STEM Camp (HS) >
      • The Teachers (2021)
      • PreAcademy prep
      • Day 1: Basics, Lights, and Temperature Sensor >
        • Day 1 Supplement: Measure Temperature
        • Day 1 Supplement: IR Temp Sensor
        • Day 1 Supplement: Identifying Resistors
        • Supplement: Controlling A Servo
      • Day 2: Measuring Pulse >
        • How the body absorbs light
        • IR Light Proximity Sensor
        • PIR Motion Sensor
      • Day 3 Supplement: OLED Screen Basics >
        • Display Screen Temperature
        • Scrolling Screen Graph
      • Day 4: Finishing up/Show
    • 2021 STEM Camp (MS) >
      • PreAcademy prep
      • Day 1: Basics, Lights, and Temperature Sensor >
        • Day 1 Supplement: Identifying Resistors
        • Day 1 Supplement: Measure Temperature
        • Day 1 Supplement: IR Light Proximity Sensor
      • Day 2: Ultrasound >
        • Day 2 Supplement: IR Temp Sensor
        • Day 2 Supplement: Controlling A Servo
      • Day 3: Measuring Pulse
    • 2020 STEM Camp
    • 2018 Lessons
    • 2017 Camp
  • Contact Us!

Proximity Sensor


IR obstacle sensor - is something in front of me? 

This sensor's only job is to tell if something is in front of it or not. It is easy to wire to the Arduino. See the picture to the right to see how to wire it. 
Picture
Picture
The clear LED is an IR lightbulb. The dark bulb is a IR phototransistor. Phototransitors are devices that amplify current more when more light shines on it. The sensor works by emitting light in front of it and then the detector measures the amount of light reflection. The little screw on the board is a variable resistor that you can use to set the detection threshold. If the detector receives enough light, it outputs that something is there! 

 Plug the sensor into the Arduino, like the picture above. Then point a digital camera, like your cell phone or webcam, at it and see if you can see the light using the camera.
Note, only some cameras can see the light! 
The lightbulb not emitting visible light. It is only emitting a specific wavelength of infrared light (IR)! That means it is not visible to your eye.
Picture

Look at this picture and video for how this sensor works. 

Picture

The code!

This sensor gives outputs of either 0 or 1 for if something is close to it or not. This code below will print on or off readings to the Serial Plotter depending on if something is close to it or not. 
Step 1: Type out the code below in Arduino IDE
Picture

Checking your code. 

Step 2: Push the check box at the top left of the page. This verifies (aka checks) if the code should work.
It "compiles" the code. That means it turns it from human readable to computer readable language.
Picture

See if you get an error message?

Step 3: Check to see if an orange error message appears in the box at the bottom of the page. Try and fix it. If you cannot figure it out, ask your teacher for help. 
Picture

Sending the code to the Arduino

Step 4. Upload your code to the board 
     a) Plug the USB cord to the Arduino and computer. 

     b) Select the right arrow button (next to the check mark) to send your code to the board. 
Picture
Picture

Did you get an error? (Is it working right?) 

You may get a "Problem uploading to board" or something similar.
If you do, it is because your Arduino does not know where the Arduino is plugged in. Or, your USB cord may not be plugged all the way in. 
Follow the steps in the picture below if you get the Port Error. 
​
          Open the tools tab, Port, and select the port COM that says Arduino. 
Picture
Step 4) If you fixed the port, push the arrow button at the top again.
Give the board a second to upload, it should be blinking quickly and then run your code.


​Let your teacher know if it still does not work and you need help. ​

Serial Monitor: Seeing what Arduino is saying :) 

The Serial Monitor is where you can see text or data that the Arduino is outputting. After you upload your code to the board successfully, select the magnifying glass on the top right of the IDE. 
Picture
After you click that button, a separate window will open up after a few seconds. 
​It will also restart your Arduino. After a few seconds, you will start seeing your proximity sensor data appear. A new line will appear every 1/5th of a second code's delay value was 200 ms or .2 sec.  
The data will read on or off if you are close vs far from the senor. See the example below.
Picture

Buzz and Light up when Close

There is not that much you need to add to this code to get the onboard LED to light up when something sets off the proximity sensor. All I did was add to the if else statement High/Low digital writes and declaring the builtin LED's pin mode in setup. 

Once you get this to work, you can wire up whatever you want to pin 13 to set it off when the sensor is triggered. Maybe add a buzzer so you hear when something is close? 

Picture
Proudly powered by Weebly
  • Home
  • 2025 RCC Camp
    • Day 1: Basic Coding >
      • Button Control
      • Multicolor LED
      • Fading multicolor led
      • Melody (sound)
    • Day 2: Servos and Potentiometers >
      • DC Motor
      • Ultrasound
      • Potentiometer and Motors
      • 2 servo control >
        • Analog Stick Control
      • PIR Motion Sensor
      • IR Light Proximity Sensor
    • Day 3 Making an ECG/EKG! >
      • ECG/EKG health lesson
      • OLED Screen Basics
      • Pictures to OLED
      • BPM on OLED
    • Day 4: Measuring Pulse >
      • Scrolling Screen Graph
      • How the body absorbs light
      • Screen Pictures
      • IR Temp Sensor And Screen
    • Day 5: Finishing up/Show >
      • IR Light Proximity Sensor
      • PIR Motion Sensor
      • CO2 Sensor
      • Ultrasound distance sensor
  • The Teachers
  • Our Partners
  • Archive
    • 2024 Health-STEM Coding Camp >
      • Home (2024)
      • The Teachers
      • Day 1: Basics and Lights
    • 2024 Coding/Robotics Camp >
      • Day 1: Basic Coding >
        • Saving your codes
        • Engineering design
      • Day 2 Servos >
        • 2 Servos, one potentiometer
        • Multicolor LED >
          • Fading multicolor led
    • Pictures from prior years
    • 2023 3D Design Camp >
      • Day 1: 2D design
      • Day 2: 3D design basics
      • Day 3: Constraints
    • 2023 Health-STEM Coding Camp >
      • PreAcademy prep
      • Day 1: Basics and Lights >
        • Multicolor LED
        • Button Control
      • Day 2: Ultrasound >
        • Ultrasound Health Lesson
        • Supplement Melody
        • Supplement: Servo >
          • Potentiometer and Motors
          • 2 servo control
      • Day 3: Measuring Pulse >
        • How the body absorbs light
        • OLED Screen Basics >
          • Scrolling Screen Graph
      • Day 4 Making an ECG/EKG! >
        • ECG Health Lesson
        • Pictures to OLED
        • BPM on OLED
      • Day 5: Finishing up/Show
    • 2021 STEM Camp (HS) >
      • The Teachers (2021)
      • PreAcademy prep
      • Day 1: Basics, Lights, and Temperature Sensor >
        • Day 1 Supplement: Measure Temperature
        • Day 1 Supplement: IR Temp Sensor
        • Day 1 Supplement: Identifying Resistors
        • Supplement: Controlling A Servo
      • Day 2: Measuring Pulse >
        • How the body absorbs light
        • IR Light Proximity Sensor
        • PIR Motion Sensor
      • Day 3 Supplement: OLED Screen Basics >
        • Display Screen Temperature
        • Scrolling Screen Graph
      • Day 4: Finishing up/Show
    • 2021 STEM Camp (MS) >
      • PreAcademy prep
      • Day 1: Basics, Lights, and Temperature Sensor >
        • Day 1 Supplement: Identifying Resistors
        • Day 1 Supplement: Measure Temperature
        • Day 1 Supplement: IR Light Proximity Sensor
      • Day 2: Ultrasound >
        • Day 2 Supplement: IR Temp Sensor
        • Day 2 Supplement: Controlling A Servo
      • Day 3: Measuring Pulse
    • 2020 STEM Camp
    • 2018 Lessons
    • 2017 Camp
  • Contact Us!