HC-12 ReadADC & Transmit

The bear

Senior Member
Hi Everyone,
The program runs via a 4v5 power supply, so power consumption is not an issue.

It transmits ADC to an indoor blind, open when light & shut at dusk.

What I would like to do is; after dusk (Dark) is to shut down transmission until dawn.

I've tried Setint / interrupt, but that didn't work (No prizes).
Any suggestions would be appreciated, program attached, warts and all!
Thank you, bear..

Code:
			;HC-12 Master ReadADC v1.1 10.02.18
			#Picaxe 08M2  	;Transmit Prog
			#No_data		;127 Bytes
			#Com 3
			;LET dirsC = %0000111 
			;SETFREQ M4
			#Terminal 4800		
		;HC-12 on Chan 2	
			; Transmitter in the shed
		Symbol baud = T2400_4      ;baud rate to use
		Symbol isensor = C.2		;ADC. input
		Symbol outpin = C.4      ;Pin connected to HC-12 RX
		Symbol inpin = C.3 
		Symbol adcval_2 = w2
		Symbol adcval_1 = w1 	
		;Symbol counter = b0		
		
		Sertxd("HC-12 Master ReadADC v1.1 10.02.18",13,10)
		;Sertxd("MARKS TEMP12  v1.3 06.01.18",13,10)

Main:			
		High outpin ;Do this or the first serout will send rubbish
		
			;From hippy
;Symbol adc_pin = C.2
	Do	
		  Readadc isensor, adcval_1
		  time = 0
		  Do
		    Readadc isensor, adcval_2
		    w1 = w1 + w2 / 2
		   ; Sertxd (#time)
	Loop Until time >= 60 ;secs
		  ;Sertxd( #w1, Cr, Lf )
	  	
			Pause 1000
	 	Serout outpin,baud,(#w1, " ADC")
			Pause 100
			;Serout outpin,baud,( " ADC  ")
		;Sertxd( " ADC = ", #w1,"  ", Cr, Lf )
			;Sertxd("ADC = ", w1,"  ", Cr, Lf ) 
			Pause 2000;0
	Loop
 

techElder

Well-known member
Hey, bear!

Seems to me one way you could do that is to stay in the readadc loop after dark. Something like this:

Code:
Do	
   Readadc isensor, adcval_1
   time = 0
   Do
      Readadc isensor, adcval_2
      w1 = w1 + w2 / 2
   Loop Until time >= 60 [COLOR="#FF0000"]AND adcval_2 => SOME_DARK_NUMBER   ; possibly "<=" depending on your sensor and sensor wiring[/COLOR]
 

AllyCat

Senior Member
Hi,

Both marks and I have posted code to calculate sunrise/sunset times to within a few minutes. Marks' program may need some modification to handle "high" latitudes (>50 degrees as in UK), mine will handle "any" latitude but admittedly is quite complex. You can take your choice. ;)

Of course you might need a RTC, but it may be possible to rely on PICaxe "time" with some correction since the progress of sunrise/sunset times should be fairly easy to "confirm" from the light level.

Cheers, Alan.
 

The bear

Senior Member
@Hi Tex,
Thanks for your input, will study your suggestion. How do I shut-down the transmitter, then re-activate it at dawn?

@ AllyCat,
Thank you for your suggestion too, bears don't do complex, well, this one doesn't.
I'm at my limit with the posted program, trying to do better and enjoying the process.

Multi-tasking at the moment, Picaxe & painting kitchen cupboards.

Regards, bear
 

techElder

Well-known member
bear, you fooled us a bit by switching from your symbols (adcval_1 and adcval_2) to the variable names (w1 and w2). That's a bit confusing.

If your code works as you have shown it, then adding the (untested) suggestion would not change anything except that you will be stuck in that DO/LOOP until your sensor sees the right light. You don't get into the transmitter code.

You just have to find the right combination of sensor type, sensor wiring and dark value. That's your job, but a schematic of how you have it wired would help us help you with that part.
 

The bear

Senior Member
Hi,
Circuit to follow, assume correct download circuit (Not shown).

HC-12 ADC TX #1.jpg

Regards, bear..
 
Last edited:

PieM

Senior Member
How do I shut-down the transmitter, then re-activate it at dawn?
Hi,
Connect pin SET to a low state pin, send the command "AT+SLEEP", and return to a high state. (16mA --> 22µA )
To exit sleep mode, send a negative pulse to this pin SET.
 

techElder

Well-known member
Ok, so LIGHT is pulling your isensor value toward a higher voltage. (BTW, I would put some capacitance on the 'upper' end of the potentiometer to smooth out any glitches from the sensor. A lot of capacitance will make the change from different light levels slower. You could even filter out a quick shadow.)

So, your test in the LOOP statement would be what I guessed at originally; => some number means that there is sufficient light to need to close the shades, and if it is < some number then the DO/LOOP keeps recirculating.

Of course, assuming that time >= 60 to move on to the transmitter.
 

The bear

Senior Member
@ PieM,
Thank you for your suggestion, looks good, due to my limitations, I assumed 'SET' was for initial configuration only.
Will check it out later.

Regards, bear..
 

newplumber

Senior Member
from Allycat post #3
Both marks and I have posted code to calculate sunrise/sunset times to within a few minutes. Marks' program may need some modification to handle "high" latitudes (>50 degrees as in UK), mine will handle "any" latitude but admittedly is quite complex. You can take your choice.
Someday I am going to try the blind/shade thing with the awesome sunrise/sunset off a RTC ..my outdoor light works perfect, thanks from Marks help on the code
and I agree with you Allycat ...your a wizard...most of your programs (which are awesome) are .....hmmm (thinking) ....."quite complex" but awesome that forum has them

@ the bear...IMHO I say throw out all your sensors/wiring/code...grab a RTC ....and your golden
but that's my two cents and I have been wrong 99 times out of 80.
 

The bear

Senior Member
@ newplumber,
Thanks, I have a RTC, but at present its a stand-alone job.
Cannot marry them up yet, due to <experience.
I haven't worked out yet, how to set an alarm on the RTC.

Regards, bear..
 

techElder

Well-known member
@ PieM,
Thank you for your suggestion, looks good, due to my limitations, I assumed 'SET' was for initial configuration only.
Will check it out later. Regards, bear..
Your original post said that you weren't worried about power consumption, so there's no need to do anything to the HC-12 transceiver. Yes, it is possible to get it to go to sleep, but why? You aren't running on batteries (according to your first post.)

Get it to work in as simple a way possible, then you can add features. (Where have I heard that before? HIPPY! :D)
 

The bear

Senior Member
@ Tex,
I don't think it could get more simple, even by my standards!

Two objects; Reduce unnecessary transmissions & improve my learning. I really like those HC-12's, (thanks Jeremy Harris).

Regards, bear..
 

techElder

Well-known member
Not to beat on a dieing horse (;)), the idea was that the transmit serial would never happen after dark.

Actually, you have a lot to do in code that you aren't showing us here. I hope you've got more code. :D
 

The bear

Senior Member
@ Tex,
That's the complete TRANSMIT code, you did say "Keep it simple".
If it doesn't work out, I can live with that!

bear..
 

techElder

Well-known member
Ok, be sure and decide what to do about flashing lights at night, flashlights at night, fireflies, low flying airplanes, chitter and chatter, tree limbs moving in the night from the wind, dirt, birds flying by and just birds. ;)

I know, bells and whistles! :D
 

The bear

Senior Member
@ Tex,
The sensor is quite stable.
We are in the sticks/outback/prairie, well, no street lights, OK we have some owls & bats, the odd Chinook.
We have an army camp not too far away.
The TX program has been working for a month, and has been monitored on a separate HC-12 RX.

bear..
 
Top