## The question requires
the use of microcontrollers and sensors to collect lighting data in real time and adjust the angle of solar panels to maximize revenue.
## Problem analysis This design uses the STC15 series microcontroller as the main control, and uses 4 photosensitive modules as light collection. At the same time, it uses the AD conversion function of the microcontroller to collect the battery panel voltages in 4 directions to determine which direction has higher light intensity. , thereby using the microcontroller to control the two-way servos to adjust the angle. ##
Tips: Overall design scheme block diagram
Column: ![image.png]
System block diagram## Schematic design description The schematic diagram is drawn using Lichuang EDA (Professional Edition). The schematic diagram includes the main control circuit, display interface circuit, and power supply circuit. , LED display circuit, voltage acquisition circuit, servo interface circuit, independent button circuit, photosensitive module acquisition circuit. ![image.png]
The picture above shows the main control circuit. The main control chip uses STC15F2K60S2. The minimum system of the main control chip is drawn in the picture. XI and XO are external crystal oscillator input and output interfaces. This design uses a 12M passive crystal oscillator to provide the clock for the main control chip. The chip has its own internal clock, so it does not need to be connected to an external crystal oscillator. But the internal one is not as stable as the external one, so I used an external clock. Reset circuit: The reset port needs to collect high-level pulses for more than 24 clock cycles before it can be reset. So I used a button to achieve manual reset. ![image.png]
The signal acquisition circuit uses a potentiometer to divide the voltage input from the battery panel to prevent excessive voltage from flowing into the pins of the microcontroller and damaging the microcontroller. The microcontroller collects the voltage value input by the battery panel through the pin with AD conversion function. The photoresistor module directly outputs a digital signal and sends it to the microcontroller, which collects it through the RIN1~4` pins. ![image.png]
The LED part is designed with 6 LED lights, two are power indicator lights, and the remaining four are direction indicator lights. When the servo deflects a certain angle in a certain direction, the corresponding microcontroller pin Output low level and light up the corresponding LED to prompt. ![image.png]
In the system power supply part, the 6P TYPEC interface is used as the power input interface, and the toggle switch is used as the power input switch. In the design, the OLED display panel requires 3.3V power supply. Here I used the ASM1117 3.3 voltage conversion chip. The 5V voltage is stepped down to 3.3V and supplied to the OLED. ![image.png]
The servo power supply is independent. If the servo and the system share a power supply, the power supply will be more demanding and may not be able to carry so many loads. So I used an independent TYpec power supply for the servo power supply. , ![image.png]
Independent button module: The microcontroller pin interface defaults to high level. Press the button to pull the microcontroller pin low, and realize button debounce through software. Each button corresponds to a different pin and triggers a different function. The reset button of the microcontroller has been configured as an IO port for use, and functions as a mode switching button. ![image.png]
Display module: The 0.91-inch OLED used is a bare screen 0.8 that I bought from Laowang on Taobao. The display driver PCB is an open source in the Lichuang Open Source Community [Laowang 0.8 yuan 128x32 OLED display converter Board connection - Lichuang EDA open source hardware platform (oshwhub.com)](https://oshwhub.com/C6C6C6C6C6/lao-wang_12832-oled) (Thanks to the author). The screen driver is 1306, 30 pins. The communication method is SPI. ## PCB design description In terms of PCB design, there is nothing that needs to be said except that the line width of the power line should be set thicker. This PCB is designed to be relatively small, so pay attention to the position when placing components. ## Software description
tip: The software can be nested using code blocks. There is no need to explain all software parts, just the important parts.
** Code block: **
uint Get_ADC10bitResult(uchar channel) //channel = 0~7 { ADC_RES = 0; ADC_RESL = 0; ADC_CONTR = (ADC_CONTR & 0xe0) | ADC_START | channel; nop(); nop(); nop(); nop(); while((ADC_CONTR & ADC_FLAG) == 0); ADC_CONTR &= ~ADC_FLAG; //Return 10-bit AD value return (((uint)ADC_RES << 2) | (ADC_RESL & 3)); } //AD channel configuration program uchar i; for(i=0;i<10 ;i++) { x0+=Get_ADC10bitResult(0); x1+=Get_ADC10bitResult(1); y0+=Get_ADC10bitResult(2); y1+=Get_ADC10bitResult(3); } ; y1=y1/30; //AD acquisition 30 times and take the average value void Timer0_Init(void) { TMOD |=0x01; TH0=-high_ms>>8; TL0=-high_ms; TR0 = 1; //Timer 0 starts timing EA = 1; ET0 = 1; } //Timer initial program void timer() interrupt 1 { switch(Pwm_Flag) { case 1: PWM=1; TH0=-pwm[0]>>8; TL0= -pwm[0]; break; // High level duration pwm[0] case 2: PWM=0; TH0=-(high_ms-pwm[0])>>8; TL0=-(high_ms-pwm[0 ]); break; //Low level time 10-pwm[0] ms case 3: PWM2=1; TH0=-pwm[1]>>8; TL0=-pwm[1]; break; //High power Flat duration pwm[1] case 4: PWM2=0; TH0=-(high_ms-pwm[1])>>8; TL0=-(high_ms-pwm[1]); break; //Low level time 10 -pwm[1] ms default:
TH0=0xff; TL0=0x80; Pwm_Flag=0; } Pwm_Flag++; } //Timer interrupt subroutine, used to generate pulses to drive the servo. ## Physical Display Instructions##
Notes: Here are some precautions that need to be paid attention to in the production of the work (if not, you can leave it out)
## Demonstration Video
Tips: You can upload attachments to the demonstration video. Attachments can only be long-distance uploaded files of up to 50M. Files larger than 50M can be placed on other network disks or video websites. Just put the address link here. ## Tips
for uploading other attachments
: Works participating in the event must upload project-related program attachments to the open source platform or personal code storage cloud. Attachments can be uploaded up to 50M (please do not upload them in the Lichuang workspace, there are restrictions)
! [20220424_224621.jpg]