Mission 6 - Distance Sensor Sound Device
 DuinoKit Jr. - View Only. See new "Mission Manual" forum for manual and code   Started by Daniel Alich   2017-06-27 18:32:56 -04:00   Comments: 4    Viewed: 2551

  1. Daniel Alich
    Daniel Alich Member Staff Member
    252_1498602709_Mission 6-1.jpg

    252_1498602698_Mission 6-2.jpg

    HC-SR04 Ping distance sensor]
    VCC to arduino 5v GND to arduino GND
    Echo to Arduino pin 3
    Trig to Arduino pin 2
    + to Arduino pin 4
    - to Arduino GND
    This sketch will also display distance values in Serial Monitor

    #define trigPin 2
    #define echoPin 3
    #define buzzer 4

    void setup() {
    Serial.begin (9600);
    pinMode(trigPin, OUTPUT);
    pinMode(echoPin, INPUT);
    pinMode(buzzer, OUTPUT);

    void loop() {
    // One process to calculating distance using HC-SR04 Ping distance sensor
    // There are numerous examples and explinations online on how the code works
    long duration, distance;
    digitalWrite(trigPin, LOW); // Added this line
    delayMicroseconds(2); // Added this line
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(10); // Added this line
    digitalWrite(trigPin, LOW);
    duration = pulseIn(echoPin, HIGH);
    distance = (duration/2) / 29.1;
    // map the input range (in this case, 0 - 135cm from the Distance Sensor)
    // to the output pitch range (2500 - 50Hz)
    // change the minimum and maximum input numbers below
    // depending on the range your sensor's giving:
    int thisPitch = map(distance, 0, 135, 2500, 50);
    // play the pitch:
    tone(buzzer, thisPitch, 10);
    Serial.print(" cm ");
    delay(50); // delay in between reads for stability
    Daniel Alich, 2017-06-27 18:32:56 -04:00
  2. I am on Mission 6, and my duino kit jr. just started making weird cricket noises. It did not do this last time I worked on the mission. I never moved my wires from last time, and the code is the exact same. Any ideas?
    Kathryn Moore, 2017-10-30 13:09:17 -04:00
  3. Daniel Alich
    Daniel Alich Member Staff Member
    Can you attach you code or did you get it working?  Are you on battery or USB power.
    Daniel Alich, 2018-01-10 10:46:14 -05:00
  4. Ron Johnson
    Ron Johnson Member Murphy, NC
    Daniel, I think I’ll try to run this on the ATTiny85.  Are you getting any help?
    Ron Johnson, 2018-03-18 12:40:46 -04:00
  5. (You must log in or sign up to post here)

Report Post

Write your reason

Log in | Sign up
Terms & Conditions!