0

Piezo with an Arduino & photoresistor

Short video (m4v) of a piezo, photoresistor and Arduino….

Pt 1951
Here’s the breadboard view to wire this up yourself…

And.. here’s the code we used from TodBot!

 
 
int photosensorPin = 0;
int piezoPin = 9;

int val = 0;

void setup() {
  pinMode(piezoPin, OUTPUT);
}

void loop() {
  digitalWrite(piezoPin, LOW);
  val = analogRead(photosensorPin);
  val = val/2;

  for( int i=0; i// play it for 50 cycles
    digitalWrite(piezoPin, HIGH);
    delayMicroseconds(val);
    digitalWrite(piezoPin, LOW);
    delayMicroseconds(val);
  }
}


 

Join 7,000+ makers on Adafruit’s Discord channels and be part of the community! http://adafru.it/discord

CircuitPython in 2018 – Python on Microcontrollers is here!

Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.

Join us every Wednesday night at 8pm ET for Ask an Engineer!

Follow Adafruit on Instagram for top secret new products, behinds the scenes and more https://www.instagram.com/adafruit/


Maker Business — The many, many manufacturing processes listed on Wikipedia

Wearables — A bevel illusion

Electronics — Blown transistor?

Biohacking — We are Wired to Exercise at a Moderate Pace

Python for Microcontrollers — Make It Move with Crickit!

Get the only spam-free daily newsletter about wearables, running a "maker business", electronic tips and more! Subscribe at AdafruitDaily.com !



5 Comments

  1. Cool little project. I just bought a photoresistor but didn’t know what to do with it. I’ll try this soon!

    Also: how did you do the breadboard/Arduino diagram? From scratch or is there a template that can be used with other software?

  2. check out fritzing.org – that’s how we make the diagrams.

  3. It looks like the source code was accidentally mutilated.

  4. fixed – we were adding some new formatting.

  5. The “for” Loop needs to be updated with “piezoPin” instead of “speakerPin” in the digitalWrite elements.

Sorry, the comment form is closed at this time.