clap clap switch

ajcgkm

New Member
Hi this is my third picaxe project that has worked. Quick vid on youtube

http://www.youtube.com/watch?v=BIpnQxuN0gY

two transisters amplify the mic send a signal to the picaxe 08m2 which then reads the first clap goes to a for loop and then checks every cycle for another clap before the loop runs out. If it reads another clap it jumps to see if the light's on or off and does the necessary job then returns waiting for input. There is another transistor used to up the current from the output of the 08m2 the relay needs 32.5mA to switch on. That was fun working that problem out.

The relay is switching 240 volts I bought a project box from ebay to house the workings and being 240v for safety as well. If you check out my other vids there is a breadboard version but works off a single clap or sneeze or cough so a lot of false triggering hence I opted for the double clap program

here is link for single clapper on the breadboard

http://www.youtube.com/watch?v=Q1UymN0OTH0&feature=relmfu

I will post the code shortly as I have seen others looking for this type of thing and not much in the way of help coming forward so check back.
 

MPep

Senior Member
Good job.
Did you decide on the second 'clap' activation after getting erroneous triggers?
 

ajcgkm

New Member
Thanks Mpep and yes it seemed that if my daughter sneezed or coughed it came on so she gave the orders to modify it. The code is below nice and simple could probably be improved upon but does what it says on the tin :p

Just waits for a clap ( or loud sound) then jumps to a sub routine that uses a for next loop to wait for another clap (or loud noise) if it receives one then jumps to the light on off routine if not it resets the first clap and goes back to the start.

As the meerkats say simples

Code:
'* clap clap switch V1 *
'* by AJ May 2012      *

symbol clap1 = b0 'first clap
symbol clap2 = b1 ' second clap
symbol counter = b2 ' counter for countdown
symbol light_condition = b3 ' light condition on or off

main:
 readadc c.4,clap1 'read pin 4 for input
 if clap1 >157 then gosub countdown '' only do this if clap is heard
goto main

countdown:
 for counter = 0 to 250' use this as a timer
  readadc c.4,clap2 ' watch pin 4 for another clap
  if clap2 >157 then gosub switch_action' if a clap is heared do this
 next counter
 clap1 =0 ' no clap so reset clap1
 clap2 =0 ' reset clap2
return

switch_action:
 counter =250 '' when returned countdown is set to 0 and for loop will end
 light_condition = light_condition +1 ' this is to set light condition
 if light_condition = 1 then high c.2 ' if condition is 1 turn light on
 end if
 if light_condition = 2 then gosub turn_off ' otherwise light is on so turn it off
return

turn_off:
 low c.2
 light_condition =0
return
 
Top